<template>
<Card style="height:800px">
    <Row>
        <Col>
        <Table :columns="columns1" :data="pageList.data"></Table>
        </Col>
    </Row>
    <br>
    <Row type="flex" justify="center" align="middle">
        <Col>
        <Button type="primary" @click="handleAdd">新增机构</Button>
        </Col>
        <Col>
        <Button type="primary" @click="handleEdit">编辑</Button>
        </Col>
        <Col>
        <Button type="error" @click="handleDel">删除</Button>
        </Col>
    </Row>
</Card>
</template>

<script>
export default {
  data () {
    return {
      baseUrl: this.$appContext.marvels_core_system,
      $ajax: null,
      columns1: [{
        align: 'center',
        title: '机构代码',
        key: 'orgCode'
      },
      {
        align: 'center',
        title: '机构名称',
        key: 'orgName'
      },
      {
        align: 'center',
        title: '机构描述',
        key: 'description'
      },
      {
        align: 'center',
        title: '上级机构',
        key: 'parentOrgName'
      },
      {
        align: 'center',
        title: '最后更新时间',
        key: 'updatedDate',
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('span', vm.$util.formatTime(params.row.updatedDate))
          ])
        }
      },
      {
        align: 'center',
        title: '最后更新人员',
        key: 'updatedBy'
      }
      ],
      pageList: {
        data: [],
        pageTotal: 0,
        pageNum: 0,
        pageSize: 20
      },
      choosedOrg: {}
    }
  },
  methods: {
    handleAdd () {
      this.$router.push({
        name: 'orgEditor',
        query: {
          type: 1,
          orgId: this.choosedOrg.orgId
        }
      })
    },
    handleEdit () {
      this.$router.push({
        name: 'orgEditor',
        query: {
          type: 2,
          orgId: this.choosedOrg.orgId
        }
      })
    },
    handleDel () {
      var vm = this
      var onedata = this.choosedOrg
      this.$Modal.confirm({
        content: '确认删除该节点【' + onedata.orgName + '】及其子节点吗？',
        onOk: function () {
          vm.$ajax.post(vm.baseUrl + 'system/pmsn/service/delOrg', onedata).then(re => {
            var data = re.data
            var code = data.code
            var message = data.message
            if (code !== 'success') {
              this.$Message.warning(message)
              return
            }
            vm.$router.back()
          }).catch(er => {

          })
        }
      })
    },
    initpage: function () {
      var params = this.$route.query || {}
      // this.chooseorg = params.data;
      if (params.orgId) {
        this.getOrgInfo(params.orgId)
      }
    },
    getOrgInfo: function (orgId) {
      var vm = this
      var org = {
        'orgId': orgId
      }
      this.$ajax.post(this.baseUrl + 'system/pmsn/service/getOrgInfo', org).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.pageList.data = [data.data]
        this.choosedOrg = data.data
      }).catch(er => {

      })
    }
  },
  mounted () {
    this.$ajax = this.$util.ajax()
    this.initpage()
  },
  created: function () {

  }
}
</script>
